cc.Class({
    extends: cc.Component,

    properties: {
        // foo: {
        //    default: null,      // The default value will be used only when the component attaching
        //                           to a node for the first time
        //    url: cc.Texture2D,  // optional, default is typeof default
        //    serializable: true, // optional, default is true
        //    visible: true,      // optional, default is true
        //    displayName: 'Foo', // optional
        //    readonly: false,    // optional, default is false
        // },
        // ...
        _userinfo: null,
        _exitbtn: null,
    },

    // use this for initialization
    onLoad: function () {
        if (cc.vv == null) {
            return;
        }

        this._userinfo = cc.find("Canvas/userinfo");
        this._userinfo.active = false;
        cc.vv.utils.addClickEvent(this._userinfo, this.node, "UserInfoShow", "onClicked");
        cc.vv.userinfoShow = this;
        this._exitbtn = cc.find("Canvas/userinfo/btn_exit");
        if (this._exitbtn) {
            cc.vv.utils.addClickEvent(this._exitbtn, this.node, "UserInfoShow", "onExitBtnClick");
        }
    },

    show: function (name, userId, iconSprite, sex, ip) {
        console.log(sex + '------')
        if (userId != null && userId > 0) {
            this._userinfo.active = true;
            this._userinfo.getChildByName("headimg").getChildByName("icon").getComponent(cc.Sprite).spriteFrame = iconSprite.spriteFrame;
            this._userinfo.getChildByName("name").getComponent(cc.Label).string = name;
            this._userinfo.getChildByName("ip").getComponent(cc.Label).string = "IP: " + ip.replace("::ffff:", "");
            this._userinfo.getChildByName("id").getComponent(cc.Label).string = "ID: " + userId;
            var sex_female = this._userinfo.getChildByName("sex_female");
            var sex_male = this._userinfo.getChildByName("sex_male");

            sex_female.active = sex == 1;
            sex_male.active = sex == 2;
        }
    },

    onClicked: function () {
        this._userinfo.active = false;
    },
    onExitBtnClick: function () {
        cc.vv.userMgr.outlogin();
        cc.vv.http.url = cc.vv.http.master_url;
    }
    // called every frame, uncomment this function to activate update callback
    // update: function (dt) {

    // },
});
